dojo.provide("medryx.rpc.tests.UserServiceTest");
dojo.require("medryx.rpc.UserService");
dojo.require("doh.runner");

var userService = new medryx.config.rpcService(medryx.rpc.UserService);

doh.register("medryx.rpc.tests.UserServiceTest",
[
{   name:"testBadLogin",
    timeout:2000,
    runTest: function() {
        var d = new doh.Deferred();
		
		userService.login("badUsername1", "badPassword1")
		  .addCallback(d.getTestCallback(function(result){
		  	   doh.assertEqual("false", result);
		  }));
		
		return d;
	}
},
{   name:"testGoodLogin",
    timeout:2000,
    runTest: function() {
        var d = new doh.Deferred();

        userService.login("user1", "pass1")
           .addCallback(d.getTestCallback(function(result){
               doh.assertEqual("public", result);
          }));
        
        return d;
    }
},
{   name:"testErrorLogin",
    timeout:2000,
    runTest: function() {
		var d = new doh.Deferred();
        userService.login("", "")
	      .addErrback(d.getTestCallback(function(error) {
			doh.assertEqual(99, error.code);
		}));
		
        return d;
    }
},  
{   name:"testLoginTooFewParams",
    timeout:2000,
    runTest: function() {
        try {
			userService.login("username");
			doh._AssertFailure("should not get here. there should be an exception!");
		} catch (err) {
			doh.assertEqual("Invalid number of parameters for remote method.", err.message);
		}
         
    }
}  
]
);
